package com.xwb.controller;

import com.xwb.dao.MemberDao;
import com.xwb.dao.MessageDao;
import com.xwb.domain.Message;
import com.xwb.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.sound.midi.Receiver;

@RestController
@RequestMapping("/message")
public class MessageController {
    @Autowired
    private MessageService messageService;
    @Autowired
    private MessageDao messageDao;
    @Autowired
    private MemberDao memberDao;

    /**
     *将信息保存到表里
     */
    @PostMapping
    public Result saveMessage(@RequestBody Message message){
        boolean flag = messageService.saveInvitation(message);
        return new Result(flag ? Code.SAVE_OK : Code.SAVE_ERR, flag);
    }

//    /**
//     * 根据接收者的学号把信息发送给对应的人
//     */
//    @GetMapping("/{receiverId}")
//    public Result sendMessageToReceiver(@PathVariable String receiverId){
//        String invitationMessage = messageService.sendMessageToReceiver(receiverId);
//        Integer code = invitationMessage != null ? Code.SEND_OK : Code.SEND_ERR;
//        String msg = invitationMessage != null ? "消息发送成功" : "消息发送失败，请重试";
//        return new Result(code,invitationMessage,msg);
//    }
//
//    /**
//     * 将邀请成员的信息传到后端进行判断处理
//     */
//    @PostMapping("/{receiverId}/receiverDecision")
//    public void receiveDecision(@PathVariable String receiverId,@RequestBody Message message){
//        String receiverDecision = message.getReceiverDecision();
//        messageDao.receiveDecision(receiverId,receiverDecision);
//        if(receiverDecision.equals("agree")){
//            memberDao.insertInvitationReceiverToTeam(receiverId);
//            memberDao.updateInvitationReceiverMessage(receiverId);
//        }
//    }




}
